-------------------------------------------------------------------------------------
-- -*- coding: utf-8 -*-
--
-- @author:   zxf
-- @email:    07291@qq.com
-- @date:     2024/5/28
-- @module:   math
-- @describe: 数学库
-- @version:  v1.0
--

-------------------------------------------------------------------------------------

---@class math
local math = {}
local this = math

-- 指定坐标是否在立方体中
function this.is_pos_in_cube(rolePos, cubeCfg)
    local long = cubeCfg.long     -- x轴
    local width = cubeCfg.width   -- y轴
    local tall = cubeCfg.tall     -- z轴
    local posX = cubeCfg.x
    local posY = cubeCfg.y
    local posZ = cubeCfg.z
    -- 角色坐标
    local setX = rolePos.x
    local setY = rolePos.y
    local setZ = rolePos.z
    local topPos = { x = posX + long / 2, y = posY + width / 2, z = posZ + tall / 2 }
    local bottomPos = { x = posX - long / 2, y = posY - width / 2, z = posZ - tall / 2 }
    if setX <= topPos.x and setX >= bottomPos.x and setY <= topPos.y and setY >= bottomPos.y and setZ <= topPos.z and setZ >= bottomPos.z
    then
        return true
    end
    return false
end

-- 两点之间距离
function this.get_dis_by_pos(pos1, pos2)
    local val = (pos2.x - pos1.x) ^ 2 + (pos2.y - pos1.y) ^ 2 + (pos2.z - pos1.z) ^ 2
    local ret = (val) ^ (1 / 2)
    return ret
end

return this
